home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Magazine / C_Tutorial / Part-2 / mouse0.c < prev    next >
C/C++ Source or Header  |  1997-07-01  |  2KB  |  77 lines

  1. #include<exec/libraries.h>
  2. #include<intuition/intuition.h>
  3. #include<utility/tagitem.h>
  4. #include<graphics/text.h>
  5.  
  6. #include<string.h>
  7.  
  8. #include<clib/exec_protos.h>
  9. #include<clib/graphics_protos.h>
  10. #include<clib/intuition_protos.h>
  11.  
  12. struct Library* GfxBase;
  13. struct Library* IntuitionBase;
  14.  
  15. /* Need to give a prototype for our message handling function */
  16. void handleIDCMP(struct Window*);
  17.  
  18. void main()
  19. {
  20.     /* Open libraries... */
  21.     if(GfxBase = OpenLibrary("graphics.library",36))
  22.     {
  23.         if(IntuitionBase = OpenLibrary("intuition.library",36))
  24.         {
  25.             /* Open our window */
  26.             struct Window* win;
  27.             if(win = OpenWindowTags(NULL,
  28.                                                             WA_Left,        20,
  29.                                                             WA_Top,            20,
  30.                                                             WA_Width,        200,
  31.                                                             WA_Height,    100,
  32.                                                             WA_Flags,        WFLG_CLOSEGADGET | WFLG_DRAGBAR,
  33.                                                             WA_IDCMP,        IDCMP_CLOSEWINDOW | IDCMP_MOUSEBUTTONS,
  34.                                                             TAG_DONE,        0))
  35.             {
  36.                 /* If window opened, handle its IDCMP messages */
  37.                 handleIDCMP(win);
  38.                 CloseWindow(win);
  39.             }
  40.             CloseLibrary(IntuitionBase);
  41.         }
  42.         CloseLibrary(GfxBase);
  43.     }
  44. }
  45.  
  46. /* Our message handling code */
  47. void handleIDCMP(struct Window* win)
  48. {
  49.     char* text = "Hello World!";
  50.     int going = TRUE;
  51.     SetAPen(win->RPort, 1);
  52.     /* Loop, waiting for messages, until the close gadget clicked */
  53.     while(going)
  54.     {
  55.         struct IntuiMessage* intuimsg;
  56.         /* Wait for messages to arrive */
  57.         WaitPort(win->UserPort);
  58.         /* Messages have arrived: loop through all of them */
  59.         while(intuimsg = (struct IntuiMessage*)GetMsg(win->UserPort))
  60.         {
  61.             /* Act on this message... */
  62.             switch(intuimsg->Class)
  63.             {
  64.             case IDCMP_CLOSEWINDOW:
  65.                 going = FALSE;
  66.                 break;
  67.             case IDCMP_MOUSEBUTTONS:
  68.                 Move(win->RPort, intuimsg->MouseX, intuimsg->MouseY);
  69.                 Text(win->RPort, text, strlen(text));
  70.                 break;
  71.             }
  72.             /* Reply when finished with message */
  73.             ReplyMsg((struct Message*)intuimsg);
  74.         }
  75.     }
  76. }
  77.